package edu.sctu.liangyuxiang.day20150616;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user20 on 2015/6/16.
 */
public class UrlText {

    private String path;

    public UrlText(String path){
        this.path = path;
    }
    public void UrlText() throws Exception{
        URL url = new URL(path);
        InputStream inputStream = url.openStream();
        byte[] buffer = new byte[1024];
        int count;

        while ((count=inputStream.read(buffer))!=-1){
            System.out.println(new String(buffer,0,count));
        }
    }

    public void UrlConnecontion()throws Exception{
        URL url = new URL(path);
        URLConnection urlConnection = url.openConnection();
        InputStream inputStream = urlConnection.getInputStream();

        byte[] buffer = new byte[1024];
        int count;

        while ((count=inputStream.read(buffer))!=-1){
            System.out.println(new String(buffer,0,count));
            System.out.println(urlConnection.getContentEncoding());
            System.out.println(urlConnection.getContentLength());
            System.out.println(urlConnection.getContentType());
        }
    }
}
